#! /bin/bash

STATE_FILE='/proc/acpi/battery/BAT0/state'

beep_for_charge_ok()
{
    while (( i <= 5 )); do
       beep 2>/dev/null || echo -ne '\a'
       (( i++ ))
       sleep 1
    done
}

if [[ ! -e $STATE_FILE ]]; then
    echo "$STATE_FILE not found"
    exit 1
fi

if grep -q 'charging state:          charging' "$STATE_FILE"; then
    echo "charging"
elif grep -q 'capacity state:          ok' $STATE_FILE &&
    grep -q 'charging state:          charged' $STATE_FILE; then
    echo 'charged'
    beep_for_charge_ok
fi
